import './assets/main.css'

import { createApp } from 'vue'
import { createPinia } from 'pinia'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import '@fortawesome/fontawesome-free/css/all.css'

import App from './App.vue'
import router from './router'

//1.导入axios
import axios from './axios/index.js'
//2.与vue实例关联

import { useUserStore } from './stores/user'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'


const app = createApp(App)

const pinia = createPinia()
app.use(pinia)

// 全局挂载ElementPlus图标组件
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}
// 全局挂载userStore，供axios拦截器使用
defineUserStoreGlobal()

app.use(router)
app.use(ElementPlus)

app.mount('#app')

// 全局挂载userStore，供axios拦截器使用
function defineUserStoreGlobal() {
  // 必须在pinia use之后调用
  window.__userStore = useUserStore()
}
